#!/bin/bash
#
# Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# Override default settings for user.
customize_user() {
  local DI_USERNAME USER_CONF
  DI_USERNAME=$(installer_get "DI_USERNAME")
  USER_CONF="/var/lib/AccountsService/deepin/users/${DI_USERNAME}"

  # Disable fallback mode
  deepin-installer-settings set "${USER_CONF}" \
    "User" "XSession" "deepin"
  deepin-installer-settings set "${USER_CONF}" \
    "User" "SystemAccount" "false"

  local DI_AVATAR
  DI_AVATAR=$(installer_get "DI_AVATAR")
  if [ -f "${DI_AVATAR}" ]; then
    deepin-installer-settings set "${USER_CONF}" \
      "User" "Icon" "file://${DI_AVATAR}"
  fi

  local SYS_LIGHTDM_BACKGROUND=/usr/share/backgrounds/oem-lightdm.png
  if [ -f "${SYS_LIGHTDM_BACKGROUND}" ]; then
    deepin-installer-settings set "${USER_CONF}" \
      "User" "GreeterBackground" "file://${SYS_LIGHTDM_BACKGROUND}"
  fi
}

if [ x$(installer_get "system_info_setup_after_reboot") != xtrue ]; then
  customize_user
fi

return 0
